package com;

import com.vo.MsgTask;

import java.util.Scanner;
import java.util.concurrent.DelayQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class DelayedDemo {

    public static void main(String[] args) {
        DelayQueue queue = new DelayQueue<>();//延迟队列
        ThreadPoolExecutor threadPoolExecutor=new ThreadPoolExecutor(30,40,30,
                TimeUnit.SECONDS,queue
                , Executors.defaultThreadFactory(),new ThreadPoolExecutor.DiscardPolicy());
        threadPoolExecutor.prestartAllCoreThreads();
        MsgTask msgTask1=new MsgTask("1",1000);
        MsgTask msgTask2=new MsgTask("5",5000);
        MsgTask msgTask3=new MsgTask("5",5000);
        MsgTask msgTask4=new MsgTask("10",10000);
        MsgTask msgTask5=new MsgTask("30",30000);
        MsgTask msgTask6=new MsgTask("50",50000);
        MsgTask msgTask7=new MsgTask("100",100000);

        threadPoolExecutor.execute(msgTask1);
        threadPoolExecutor.execute(msgTask2);
        threadPoolExecutor.execute(msgTask3);
        threadPoolExecutor.execute(msgTask4);
        threadPoolExecutor.execute(msgTask5);
        threadPoolExecutor.execute(msgTask6);
        threadPoolExecutor.execute(msgTask7);


        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
//        MsgTask t10 = new MsgTask(10,10,"任务10",1000);
//        threadPoolExecutor.execute(t10);
        Scanner sc = new Scanner(System.in);
        sc.next();
    }
}
